<?php

class Jobseeker_RegisterController extends Zend_Controller_Action
{
	public function init()
	{
		
	}
	
	public function indexAction()
	{
		$model = new RP_Model_DbTable_Industry();
		$rowSet = $model->fetchAllIndustries();
		$this->view->assign('industrySet',$rowSet);
		
		$model = new RP_Model_DbTable_FunctionalArea();
		$rowSet = $model->fetchAllFunctinalArea();
		$this->view->assign('faSet',$rowSet);	
		
		$model = new RP_Model_DbTable_EduOrg();
		$rowSet = $model->fetchAllOrganizations();
		$this->view->assign('eduOrgSet',$rowSet);
	}
	
	public function getcoursesAction(){
		$this->_helper->viewRenderer->setNoRender(TRUE);
		$this->_helper->layout()->disableLayout();
		
			$request = $this->getRequest();
	        $format = $request->getParam('format', 'json');
	        $course_type = $request->getParam('course_type');
	        $model = new RP_Model_DbTable_Course();
	        $rowSet = $model->fetchAllCourses($course_type);
	        
	        switch (strtolower($format)) {
	            case 'json':
	                $this->_helper->json($rowSet);
	                return;
	            case 'jsonp':
	                $callback = $request->getParam('callback');
	                echo $callback . '(' . $this->_helper->json($result, false) . ')';
	                return;
	        }
	}
	
	public function getspecializationsAction(){
		$this->_helper->viewRenderer->setNoRender(TRUE);
		$this->_helper->layout()->disableLayout();
		
			$request = $this->getRequest();
	        $format = $request->getParam('format', 'json');
	        $course_id = $request->getParam('course_id');
	        $model = new RP_Model_DbTable_CourseSpec();
	        $rowSet = $model->fetchCourseSpecializations($course_id);
	        
	        switch (strtolower($format)) {
	            case 'json':
	                $this->_helper->json($rowSet);
	                return;
	            case 'jsonp':
	                $callback = $request->getParam('callback');
	                echo $callback . '(' . $this->_helper->json($result, false) . ')';
	                return;
	        }
	}
	
	public function registerAction()
	{
		$this->_helper->viewRenderer->setNoRender(TRUE);
		$this->_helper->layout()->disableLayout();
		$request = $this->getRequest();
		
		$param = array(
					'username'=>$request->getParam("username"),
					'password'=>$request->getParam("password"),
					'email'=>$request->getParam("email"),
					'name'=>$request->getParam("name"),
					'curr_location'=>$request->getParam("curr_location"),
					'mobile_no'=>$request->getParam("mobile_no"),
					'alternate_no'=>$request->getParam("alternate_no"),
					'exp_years'=>$request->getParam("exp_years"),
					'exp_months'=>$request->getParam("exp_months"),
					'skills'=>$request->getParam("skills"),
					'resume_headline'=>$request->getParam("resume_headline"),
					'industry_id'=>$request->getParam("industry_id"),
					'fa_id'=>$request->getParam("fa_id"),
					'ug_check'=>$request->getParam("ug_check"),
					'course_type'=>$request->getParam("course_type"),
					'course_id'=>$request->getParam("course_id"),
					'edu_spec_id'=>$request->getParam("edu_spec_id"),
					'edu_org_id'=>$request->getParam("edu_org_id"),
					'edu_style'=>$request->getParam("edu_style"),
					'year_of_passing'=>$request->getParam("year_of_passing")
		
				 );	 
		
		$logger = Zend_Registry::get("logger");
			$logger->debug($param);		
		switch($request->getParam("oper")){
			case 'add':
				
				$model = new RP_Model_User_Jobseeker($param);
				if(!$model->isUsernameAvailable()){
					echo "Username Not Available";
					return;
				}
				if(!$model->isEmailAvailable()){
					echo "Job Seeker accoount with ".$model->getEmail()." already exist.";
					return;
				}
				if($model->register()){	
					echo $model->getUsername() .
                     ' is now registered as job seeker.';
                    return;
				}
				break;
				
			default:
				throw new Zend_Exception('"' . $oper . '" is unknown operation.', 
                Zend_Log::ERR);
                break;
		}
		throw new Zend_Exception(
        'Operation on job seeker "' . $model->getUsername() . '" not successfull.', 
        Zend_Log::ERR);
	}
}